{extend name='common/content' /}

{block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
    <button data-modal='{:url("$classuri/addPosition")}' data-title="添加广告位" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加广告位</button>
    <button data-update data-field='delete' data-action='{:url("$classuri/delPosition")}' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除广告位</button>
</div>
{/block}

{block name="content"}

<form onsubmit="return false;" data-auto="" method="POST">
    <input type="hidden" value="resort" name="action"/>
    <div class="layui-form">
        <table class="table table-hover">
            <thead>
            <tr>
                <th>
                    <input data-none-auto="" data-check-target='.list-check-box' lay-skin="primary" lay-filter="allChoose" type="checkbox">
                </th>
                <th>广告位名称</th>
                <th>调用代码</th>
                <th>宽度（px）</th>
                <th>高度（px）</th>
                <th class='text-center'>状态</th>
                <th class='text-center'>操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $list as $key=>$vo}
            <tr>
                <td>
                    <input class="list-check-box" value='{$vo.id}' lay-skin="primary" type="checkbox">
                </td>
                <td>
                    <a data-open='{:url("$classuri/index")}?position_id={$vo.id}'>{$vo.position}</a>
                </td>
                <td>
                    <span style="background: #4b4b4b;color: #fff;padding: 0 5px;border-radius: 5px;">{:get_ad({$vo.id}, $limit = 1)}</span>
                </td>
                <td>{$vo.width|default="<span style='color:#ccc'>暂未设置宽度</span>"}</td>
                <td>{$vo.height|default="<span style='color:#ccc'>暂未设置高度</span>"}</td>
                <td class='text-center'>
                    {if $vo.status eq 1}
                    <span style="color:#090">启用</span>
                    {else/}
                    <span>禁用</span>
                    {/if}
                </td>
                <td class='text-center nowrap'>
                    {if auth("$classuri/add")}
                    <span class="text-explode">|</span>
                    <a data-modal='{:url("$classuri/add")}?position_id={$vo.id}' href="javascript:void(0)">添加广告</a>
                    {/if}
                    {if auth("$classuri/editPosition")}
                    <span class="text-explode">|</span>
                    <a data-modal='{:url("$classuri/editPosition")}?id={$vo.id}' href="javascript:void(0)">编辑</a>
                    {/if}
                    {if $vo.status eq 1 and auth("$classuri/forbidPosition")}
                    <span class="text-explode">|</span>
                    <a data-update="{$vo.id}" data-field='status' data-value='0' data-action='{:url("$classuri/forbidPosition")}'
                       href="javascript:void(0)">禁用</a>
                    {elseif auth("$classuri/resumePosition")}
                    <span class="text-explode">|</span>
                    <a data-update="{$vo.id}" data-field='status' data-value='1' data-action='{:url("$classuri/resumePosition")}'
                       href="javascript:void(0)">启用</a>
                    {/if}
                    {if auth("$classuri/delPosition")}
                    <span class="text-explode">|</span>
                    <a data-update="{$vo.id}" data-field='delete' data-action='{:url("$classuri/delPosition")}' href="javascript:void(0)">删除</a>
                    {/if}
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
</form>

<script>window.form.render();</script>
<script>
    layui.use('form', function(){
        var $ = layui.jquery, form = layui.form;

        //全选
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });

    });
</script>

{/block}